page.pageInit = function(){
  //初始化grid
  GirdCtr.gridInit();
  GirdCtr.buttonBind()
}

//grid控制器
var GirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#mainGrid").jqGrid({
		 			datatype: "json",
		 			url : contextPath+'/quartz/task/query.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:'任务ID', name: 'jobId',sortable:false,hidden:false,key:true,width : 80,align : "center"},
					             {label: 'bean名称', name: 'beanName',sortable:false,width : 100,align : "center"}, 
					             {label: '方法名称', name: 'methodName',sortable:false,width : 120,align : "center"}, 
					             {label: '参数', name: 'params',sortable:false,width : 120,align : "center"}, 
					             {label: 'cron表达式 ', name: 'cronExpression',sortable:false,width : 120,align : "center"}, 
					             {label: '备注 ', name: 'remark',sortable:false,width : 220,align : "center"} ,
					             {label: '状态', name: 'status',sortable:false,width : 60,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(systemDict.RunStatus)}}
					             ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#mainGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'createTime',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width,
					height:page.window.grid.height
					
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#mainGrid").jqGrid('navGrid', '#mainGridPager', {edit:false,add:false,del:false,search:false,view:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#taskAddBtn").bind("click",function(){_this.event.doAdd(_this,this)});//新增
	  $("#taskEditBtn").bind("click",function(){_this.event.doEdit(_this,this)});//编辑
	  $("#taskDeleteBtn").bind("click",function(){_this.event.doDelete(_this,this)});//删除
	  $("#taskDetailBtn").bind("click",function(){_this.event.doDetail(_this,this)});//详情
	  $("#taskStopBtn").bind("click",function(){_this.event.doStop(_this,this)});//暂停
	  $("#taskReBackBtn").bind("click",function(){_this.event.doReback(_this,this)});//恢复
	  $("#taskStartBtn").bind("click",function(){_this.event.doStart(_this,this)});//立即执行
	  $("#taskLogBtn").bind("click",function(){_this.event.doLog(_this,this)});//日志
	 
	}, 
	event:{//事件
	  doAdd:function(_this,btn){
		      var menuId = $(btn).attr("menuId");
			  var params = {menuId:menuId}
			  showWindow("添加任务",contextPath+"/quartz/task/addView.htm",params,function(){
				  GirdCtr.reLoad();
			  });
	  },
	  doEdit:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.jobId}
			  showWindow("修改任务",contextPath+"/quartz/task/editView.htm",params,function(){
				  GirdCtr.reLoad();
			  });
		  }else{
			  layer.msg("选择需要修改的数据");
		  }
	  },
	  doDetail:function(_this,btn){//详情
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.jobId}
			  showWindow("查看",contextPath+"/quartz/task/detailView.htm",params,function(){
				  
			  },true);
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doStop:function(_this,btn){//暂停
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {id:node.jobId}
			  $.dataPost(contextPath+'/quartz/task/stop.htm',params,function(result){
				  if(result.success){
					  GirdCtr.reLoad();
				  }else{
					  layer.msg(result.msg); 
				  }
			  });
		  }else{
			  layer.msg("选择需要暂停的数据");
		  }
	  },
	  doReback:function(_this,btn){//恢复
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {id:node.jobId}
			  $.dataPost(contextPath+'/quartz/task/reBack.htm',params,function(result){
				  if(result.success){
					  GirdCtr.reLoad();
				  }else{
					  layer.msg(result.msg); 
				  }
			  });
		  }else{
			  layer.msg("选择需要恢复的数据");
		  }
	  },
	  doStart:function(_this,btn){//启动
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {id:node.jobId}
			  $.dataPost(contextPath+'/quartz/task/start.htm',params,function(result){
				  if(result.success){
					  GirdCtr.reLoad();
				  }else{
					  layer.msg(result.msg); 
				  }
			  });
		  }else{
			  layer.msg("选择需要启动的数据");
		  }
	  },
	  doLog:function(_this,btn){//部署
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var menuId = $(btn).attr("menuId");
			  var params = {menuId:menuId,id:node.jobId}
			  showWindow("执行日志",contextPath+"/quartz/log/view.htm",params,function(){
			  },true);
		  }else{
			  layer.msg("请选择查看的数据.");
		  }
	  },
	  doDelete:function(_this,btn){//删除
		  var id = _this.grid.jqGrid('getGridParam','selrow');
		  if(id){
			 var laIndex = layer.confirm('确定要删除该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoDelete(id,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择删除的数据.");
		  }
	  },gridDoDelete:function(id,_this){
		  $.dataPost(contextPath+'/quartz/task/delete.htm',{id:id},function(result){
			  if(result.success){
				  GirdCtr.reLoad();
			  }else{
				  layer.msg(result.msg); 
			  }
		  });
	  }
	}
});

